/**
 * 
 */
package com.fox.webapp.web.admin;

import java.util.List;

import org.bson.types.ObjectId;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.fox.webapp.domain.AccountVerifySetting;
import com.fox.webapp.service.IBrokerService;
import com.fox.webapp.service.ISettingsService;

/**
 * @author yockii
 *
 */
@Controller
@RequestMapping("admin/settings")
public class SettingsController {

	@Autowired
	private ISettingsService settingsService;
	@Autowired
	private IBrokerService brokerService;
	
	@RequestMapping(value = "autoConfirm", method = RequestMethod.GET)
	public String autoConfirmPage(Model model){
		List<AccountVerifySetting> avsList = settingsService.getAllAccountVerifySettings();
		model.addAttribute("avsList", avsList);
		return "admin/settings/autoConfirm/show";
	}
	
	@RequestMapping(value = "autoConfirm/add", method = RequestMethod.GET)
	public String addAutoConfirmPage(Model model){
		model.addAttribute("brokerList", brokerService.getAllBrokers());
		return "admin/settings/autoConfirm/add";
	}
	
	@RequestMapping(value = "autoConfirm/add", method = RequestMethod.POST)
	public String addAutoConfirm(AccountVerifySetting avs, Model model){
		settingsService.addNewAccountVerifySetting(avs);
		return autoConfirmPage(model);
	}
	
	@RequestMapping(value = "autoConfirm/update/{id}", method = RequestMethod.GET)
	public String modifyAutoConfirm(Model model, @PathVariable ObjectId id){
		model.addAttribute("avs", settingsService.getAccountVerifySetting(id));
		return addAutoConfirmPage(model);
	}
	
	@RequestMapping(value = "autoConfirm/update", method = RequestMethod.POST)
	public String modifyAutoConfirm(AccountVerifySetting avs, Model model){
		settingsService.updateAccountVerifySetting(avs);
		return autoConfirmPage(model);
	}
	
	@RequestMapping(value = "autoConfirm/remove/{id}", method = RequestMethod.GET)
	public String removeAutoConfirm(@PathVariable ObjectId id, Model model){
		settingsService.removeAccountVerifySetting(id);
		return autoConfirmPage(model);
	}
}
